﻿using LyData.Data;
using LyData.Data.Xml;
using System;
using System.Data;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Website : System.Web.UI.Page
{
    protected void Bind()
    {
        string str = SiteInfo.SiteLanguage();
        DataRow row = new XmlProvider(base.Server.MapPath("~/App_Data/Website.xml")).ReadNode(string.Format("descendant::Info[Language={0}]", str));
        if (row != null)
        {
            this.WebsiteName.Text = (string)row["WebsiteName"];
            this.WebsiteTitle.Text = (string)row["WebsiteTitle"];
            this.KeyWords.Text = (string)row["KeyWords"];
            this.Description.Text = (string)row["Description"];
            this.CopyRight.Text = (string)row["CopyRight"];
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Msg.Visible = false;
        if (!ManagerLogin.ValidateRole("B_Website.aspx"))
        {
            this.Msg.CssClass = "errorMsg";
            this.Msg.Text = "您无此权限！";
            this.Save.Enabled = false;
            this.Msg.Visible = true;
        }
        else if (!base.IsPostBack)
        {
            this.Bind();
        }
    }

    protected void Save_Click(object sender, EventArgs e)
    {
        string str = SiteInfo.SiteLanguage();
        XmlProvider provider = new XmlProvider(base.Server.MapPath("~/App_Data/Website.xml"));
        string[,] nodeDateList = new string[,] { { "Language", str }, { "WebsiteName", this.WebsiteName.Text }, { "WebsiteTitle", this.WebsiteTitle.Text }, { "KeyWords", this.KeyWords.Text }, { "Description", this.Description.Text }, { "CopyRight", this.CopyRight.Text } };
        if (!provider.ValidateNode(string.Format("descendant::Info[Language={0}]", str)))
        {
            provider.CreateNode("Doc", "Info", nodeDateList);
        }
        else
        {
            provider.ChangeNode(string.Format("descendant::Info[Language={0}]", str), nodeDateList);
        }
        this.Msg.Text = "站点信息配置更新成功！";
        this.Msg.Visible = true;
    }
}
